import {
    Result_queryTopModel,
    commitScoreModel,
    queryTopModel,
    result_commitScoreModel
} from "./typing"

export class LeaderboardService {
    private sdk
    private cloud

    constructor(cloud, sdk) {
        this.cloud = cloud
        this.sdk = sdk
    }


    // 提交或者更新分数
    public async replaceScore(data: commitScoreModel) {
        return new Promise((resolve, reject) => {
            this.sdk.callFunction({
                name: 'replaceScore',
                data: data
            }).then((res: result_commitScoreModel) => {
                if (res?.result?.res?.code !== 200) resolve(null)
                resolve(res?.result)
            }).catch((e: any) => {
                reject(e)
            })
        })
    }

    // 获取top排行
    public async getLeaderboardTopRank(data: queryTopModel) {
        console.log("getLeaderboardTopRank");
        return new Promise((resolve, reject) => {
            this.sdk.callFunction({
                name: 'getLeaderboardTopRank',
                data: data
            }).then((res: Result_queryTopModel) => {
                if (res?.result?.res?.code !== 200) resolve(null)
                resolve(res?.result)
            }).catch((e: any) => {
                reject(e)
            })
        })
    }
}
